/*
 * @Date: 2021-09-10 10:30:00
 * @Author: Acckno1
 * @LastEditTime: 2021-09-10 11:06:12
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 210;

int g[N][N];
int n, m;
int path[N];
bool st[N];
int shortest = INF, short_path;

/**
 * @description: 
 * 如果是TS cycle需要满足三个条件：
 * 1. 首尾相等
 * 2. 经过所有的点
 * 3. 在path路径中所有相互连接的边必须存在
 * 
 * 如果是TS Simple cycle需要在满足TS cycle的条件是再多满足：cnt == n + 1(即不存在重复的元素，首尾除外)
 * @param {int} cnt
 * @param {int} p 当前path 用于更新最短距离路径(short_path)
 * @return {*}
 */
pair<bool, int> check_cycle(int cnt, int p) {
    int res = 0;
    bool flag = true;
    mm(st, false);
    // 计算是否相邻之间是否有边
    for (int i = 0; i < cnt - 1; i ++ ) {
        if (g[path[i]][path[i + 1]] == -1) return mk(false, -1);
        else res += g[path[i]][path[i + 1]];
    }
    // 标记所有元素是否被访问
    for (int i = 0; i < cnt; i ++ ) st[path[i]] = true;
    for (int i = 1; i <= n; i ++ ) 
        if (!st[n]) 
            return mk(false, res);
    
    if (path[0] != path[cnt - 1]) return mk(false, res);
    // 更新最短 圈
    if (res < shortest) {
        shortest = res;
        short_path = p;
    }
    return mk(true, res);
}

bool check_simple_cycle(int cnt) {
    return cnt == n + 1;
} 

inline void solution() {
    mm(g, -1);
    cin >> n >> m;
    for (int i = 0; i < m; i ++ ) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a][b] = g[b][a] = c;
    }
    int T;
    cin >> T;
    for (int _ = 1; _ <= T; _ ++ ) {
        int cnt;
        cin >> cnt;
        for (int i = 0; i < cnt; i ++ ) cin >> path[i];
        auto p = check_cycle(cnt, _);
        cout << "Path " << _ << ": ";
        if (p.second == -1) 
            cout << "NA ";
        else
            cout << p.second << " ";
        if (p.first) {
            if (check_simple_cycle(cnt)) {
                cout << "(TS simple cycle)" << endl;
            } else {
                cout << "(TS cycle)" << endl;
            }
        } else {
            cout << "(Not a TS cycle)" << endl;
        }
    }
    cout << "Shortest Dist(" << short_path << ") = " << shortest << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}